package p4_student;

import static org.junit.Assert.*;




import org.junit.Test;



public class YourTests {
	//SOME EXAMPLE JUNIT TESTS TO GET YOU STARTED THINKING ABOUT 
	//  WRITING JUNIT TESTS
	@Test
	public void testDefaultConstructor() {
		MartianPolynomial testPoly = new MartianPolynomial();
		assertTrue(testPoly.getA().isZero()
				&& testPoly.getB().isZero()
				&& testPoly.getC().isZero());
	}
	
	@Test
	public void testSingleValConstructor() {
		MyDouble cVal = new MyDouble(27.8);
				
		MartianPolynomial testPoly = new MartianPolynomial(cVal);
		assertTrue(testPoly.getA().isZero()
				&& testPoly.getB().isZero()
				&& testPoly.getC().equals(cVal));
	}

	@Test
	public void testThreeValConstructor() {
		MyDouble aVal = new MyDouble(15.7);
		MyDouble bVal = new MyDouble(-23.7);
		MyDouble cVal = new MyDouble(4.3);
				
		MartianPolynomial testPoly = new MartianPolynomial(aVal, bVal, cVal);
		assertTrue(testPoly.getA().equals(aVal)
				&& testPoly.getB().equals(bVal)
				&& testPoly.getC().equals(cVal));
	}

	@Test
	public void testEval() {
		MyDouble aVal = new MyDouble(2);
		MyDouble bVal = new MyDouble(4);
		MyDouble cVal = new MyDouble(8);
		
		MartianPolynomial testPoly = new MartianPolynomial(aVal, bVal, cVal);
		assertTrue(testPoly.eval(new MyDouble(0)).equals(new MyDouble(8)));
		assertTrue(testPoly.eval(new MyDouble(1)).equals(new MyDouble(14)));
		assertTrue(testPoly.eval(new MyDouble(2)).equals(new MyDouble(24)));
		assertTrue(testPoly.eval(new MyDouble(3)).equals(new MyDouble(38)));
	}

	
	//YOU NEED TO IMPLEMENT AT LEAST THESE JUNIT TESTS BELOW
	@Test
	public void testGetters() {
		
		MyDouble aValue = new MyDouble(3);
		MyDouble bValue = new MyDouble(1.2);
		MyDouble cValue = new MyDouble(21);

		MartianPolynomial testPoly = new MartianPolynomial(aValue, bValue, 
				cValue);
		assertTrue(testPoly.getA().equals(aValue));
		assertTrue(testPoly.getB().equals(bValue));
		assertTrue(testPoly.getC().equals(cValue));
	}

	@Test
	public void testAdd() {
		
		MyDouble a = new MyDouble(1.0), b = new MyDouble(3.5),
				c = new MyDouble(5.0);
		MyDouble d = new MyDouble(-2.0), e = new MyDouble(4.5), 
				f = new MyDouble(1.2);
		
		
		MartianPolynomial mp = new MartianPolynomial(a,b,c);
		MartianPolynomial mpol = new MartianPolynomial(d,e,f);
		MartianPolynomial sum =mp.add(mpol);
		MyDouble actualSumA = sum.getA(); 
		MyDouble expectedSumA = new MyDouble(-1.0);
		MyDouble actualSumB = sum.getB();
		MyDouble expectedSumB = new MyDouble(8.0);
		MyDouble actualSumC = sum.getC();
		MyDouble expectedSumC = new MyDouble(6.2);

	
		assertTrue(actualSumA.equals(expectedSumA));
		assertTrue(actualSumB.equals(expectedSumB));
		assertTrue(actualSumC.equals(expectedSumC));
		
	}
	

	@Test
	public void testSubtract() {
		MyDouble a = new MyDouble(1.0), b = new MyDouble(3.5), c = new MyDouble(5.0);
		MyDouble d = new MyDouble(2.0), e = new MyDouble(4.0), f = new MyDouble(1.2);
		
		//Act
		MartianPolynomial mp = new MartianPolynomial(a,b,c);
		MartianPolynomial mpol = new MartianPolynomial(d,e,f);
		MartianPolynomial sum =mp.subtract(mpol);
		MyDouble actualSumA = sum.getA(); 
		MyDouble expectedSumA = new MyDouble(-1.0);
		MyDouble actualSumB = sum.getB();
		MyDouble expectedSumB = new MyDouble(-0.5);
		MyDouble actualSumC = sum.getC();
		MyDouble expectedSumC = new MyDouble(3.8);

		//Assert
		assertTrue(actualSumA.equals(expectedSumA));
		assertTrue(actualSumB.equals(expectedSumB));
		assertTrue(actualSumC.equals(expectedSumC));
	
	}


	@Test
	public void testEqualsAndCompareTo() {
		MyDouble a = new MyDouble(1), b = new MyDouble(3), c = new MyDouble(5);
		MartianPolynomial e1 = new MartianPolynomial(a , b, c);
		MartianPolynomial e2 = new MartianPolynomial(a , b, c);
		boolean equals = e1.equals(e2);
		assertTrue(equals);
		
		MartianPolynomial c1 = new MartianPolynomial(a, b, c);
		MartianPolynomial c2 = new MartianPolynomial(a, b, c);
		int compareTo = c1.compareTo(c2);
		assertEquals(compareTo, 0);
	
		
		
		
	}

	@Test
	public void testToString() {
		MyDouble a = new MyDouble(3), b = new MyDouble(7),
				c = new MyDouble(1);
		MyDouble d = new MyDouble(0), e = new MyDouble(1), 
				f = new MyDouble(0);

		MartianPolynomial s1 = new MartianPolynomial(a, b, c);
		MartianPolynomial s2 = new MartianPolynomial(d, e, f);
		String s1String = s1.toString();
		String s2String = s2.toString();
		String expect1String = "3x^2+7x+1";
		String expect2String = "1x";
		
		assertTrue(s1String.equals(expect1String));
		assertTrue(s2String.equals(expect2String));
		
	}
	


@Test
public void testparseMartianPolynomial(){
	
	MartianPolynomial returnedAnswer = MartianPolynomial.parseMartianPolynomial
			("-3.78x^2 + 9.0x");
	
	MyDouble coeffA = new MyDouble(-3.78);
	MyDouble coeffB = new MyDouble(9.0);
	MyDouble coeffC = new MyDouble(0);
	
	assertEquals(returnedAnswer.getA(),coeffA);
	assertEquals(returnedAnswer.getB(),coeffB);
	assertEquals(returnedAnswer.getC(),coeffC);
	
	
	
	
	
	
}
	

	
}
